var oauthClientDetailModule = angular.module('oauthClientDetailModule', ['paginationService', 'anajaxService','agularValidate','innerPaginationService']);

oauthClientDetailModule.controller('oauthClientDetailController', function($scope, $http,pagination,anajax,innerPagination) {
	
	
	$scope.resultList={};//结果列表
	$scope.queryForm={};
	$scope.oauthClientDetailForm={};
	$scope.oauthClientDetailForm.bisfreeze=0;
	$scope.bisfreezeOps={1:"是",0:"否"};
	$scope.roleList={};//用户的角色列表
	
	/**
	 * 查询
	 */
	var query = function(params) {
		var url = commonutil.actionPath + '/sso/client_details/list_json';
		anajax.doajax(url, params, function(data) {
			$scope.resultList = data.resultList;
			pagination.setData(data.pagination);
			$scope.pagination = data.pagination; 
		});
	};
	
	query($scope.queryForm);
	
	/**
	 * 跳转到指定页
	 */
	$scope.goPage = function(selNum) {
		
		pagination.goPage(selNum);
		query($scope.pagination);
	};
	
	/**
	 * 上一页
	 */
	$scope.lastPage = function() {
		pagination.lastPage();
		query($scope.pagination);
	};
	
	/**
	 * 下一页
	 */
	$scope.nextPage = function() {
		pagination.nextPage();
		query($scope.pagination);
	};
	
	/**
	 * 点击查询
	 */
	$scope.doquery = function() {
		
		query($scope.queryForm);
	};
	
	/**
	
	
	/**初始化新增*/
	$scope.goAdd = function(index) {
		$scope.oauthClientDetailForm = {};
		$scope.stations = [];
		$scope.rightPart = 'add';
		$scope.oauthClientDetailForm = {'invoice':'是'};
		removeTips($('#edit-data-warp'));
		$("#clientId").removeAttr("readonly");
		pageutil.showRightBarAn('新增客户端配置');
	};
	
	/**初始化编辑*/
	$scope.goModify  = function(index) {
		$scope.rightPart = 'edit';
		var assets=$scope.resultList[index];
		angular.copy(assets,$scope.oauthClientDetailForm);
		$scope.oauthClientDetailForm.createTime=null;
		removeTips($('#edit-data-warp'));
		$("#clientId").attr("readonly","readonly");
		pageutil.showRightBarAn('编辑客户端配置');
	};
	
	
	
	
	$scope.doCancel = function(){
		$scope.oauthClientDetailForm = {};
		pageutil.hideRightBar();
	}
	
	
	/**
	 * 执行添加
	 */
	$scope.doAdd = function() {
		var res = Validator.validate($("#edit-data-warp"));
		if(!res){
			return;
		}
		if($scope.rightPart=='add'){
			$scope.add($scope.oauthClientDetailForm);
		}else{
			$scope.modify($scope.oauthClientDetailForm);
		}
		
	};
	
	/**
	 * 执行添加
	 */
	$scope.add = function(postData) {
		var url = commonutil.actionPath + '/sso/client_details/add';
		anajax.doajax(url, postData, function(data) {
			if (data.resultValue ) {
				pageutil.showTip('添加成功');
				pageutil.hideRightBar();
				$scope.doquery();
			} else {
				pageutil.showTip(data.message);
			}
		});
	};
	
	/**
	 * 执行修改
	 */
	$scope.modify = function(postData) {
		var url = commonutil.actionPath + '/sso/client_details/edit';
		anajax.doajax(url, postData, function(data) {
			if (data.resultValue ) {
				pageutil.showTip('修改成功');
				pageutil.hideRightBar();
				$scope.doquery();
			} else {
				pageutil.showTip(data.message);
			}
		});
	};
	
	$scope.delBean ={};
	
	/**
	 * 弹出确认删除窗口
	 */
	$scope.showDelWin = function($index){
		var assetBean = $scope.resultList[$index];
		$scope.delBean= assetBean;
		$scope.delBean.createTime=null;
		$("#confirm_del_asset_div").modal('show');
	};
	
	$scope.doDelAsset = function() {
	    console.log($scope.delBean);
		var url = commonutil.actionPath + '/sso/client_details/del';
		anajax.doajax(url,$scope.delBean, function(data) {
			if (data.resultValue ) {
				pageutil.showTip('删除成功');
				$scope.doquery();
			} else {
				pageutil.showTip(data.message);
			}
		});
	};
	

	
});